package com.whmnx.home.ui.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.classic.adapter.CommonRecyclerAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.tencent.liteav.basic.log.TXCLog;
import com.tencent.qcloud.ugckit.utils.TelephonyUtil;
import com.tencent.qcloud.ugckit.utils.ToastUtil;
import com.tencent.rtmp.ITXVodPlayListener;
import com.tencent.rtmp.TXLiveConstants;
import com.tencent.rtmp.TXLog;
import com.tencent.rtmp.TXVodPlayConfig;
import com.tencent.rtmp.TXVodPlayer;
import com.tencent.rtmp.ui.TXCloudVideoView;
import com.whmnx.base.base.BaseFragment;
import com.whmnx.base.bean.BaseBean;
import com.whmnx.base.bean.LoginBean;
import com.whmnx.base.bean.PingBean;
import com.whmnx.base.bean.PlayerInfo;
import com.whmnx.base.bean.ShopShowBean;
import com.whmnx.base.bean.TCVideoInfo;
import com.whmnx.base.bean.TolalBean;
import com.whmnx.base.bean.VideoListBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.constants.EventConstants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.base.router.RouterActivityPath;
import com.whmnx.base.utils.ImageUtil;
import com.whmnx.base.utils.TCTimeUtil;
import com.whmnx.base.utils.UItils;
import com.whmnx.base.view.DynamicInputTextMsgDialog;
import com.whmnx.base.view.TCPointSeekBar;
import com.whmnx.home.R;
import com.whmnx.home.ui.activity.CompletedView;
import com.whmnx.home.ui.adapter.PingJiaListAdapter;
import com.whmnx.home.ui.adapter.ShowShopAdapter;
import com.whmnx.home.ui.adapter.VideoAdapter2;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;
import de.hdodenhof.circleimageview.CircleImageView;
import fr.castorflex.android.verticalviewpager.VerticalViewPager;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.bus.RxBus;
import me.goldze.mvvmhabit.bus.RxSubscriptions;
import me.goldze.mvvmhabit.utils.KLog;
import me.goldze.mvvmhabit.utils.SPUtils;

/**
 * author : huang
 * date   : 2020/10/24 0024 19:14
 * version: 1.0
 * @author Administrator
 */
public class TunJianFragment2 extends BaseFragment implements TelephonyUtil.OnTelephoneListener {
    private static final String TAG = "TunJianFragment2";

    private TXCloudVideoView mTXCloudVideoView;
    private VerticalViewPager mVerticalViewPager;
    private List<TCVideoInfo> mTCLiveInfoList = new ArrayList<>();

    private int mCurrentPosition;

    private PingJiaListAdapter pingJiaListAdapter;

    private MyPagerAdapter mPagerAdapter;

    private Dialog dialogHead;
    private Disposable subscribe;

    /**
     * SDK播放器以及配置
     */
    private TXVodPlayer mTXVodPlayer;
    private List<VideoListBean> videoListBean = new ArrayList<>();
    private TextView tvNme;
    private CompletedView mTasksView;

    private int mTotalProgress = 300;
    private int  playTime = 0;
    //滑动
    private boolean isPageFlag = false;
    private boolean isZhangTing2;
    private boolean isHidden;

    private RelativeLayout mRl;
    private RecyclerView rvList;
    private VideoAdapter2 videoAdapter;

    private boolean isAdapterFlag;
    private DynamicInputTextMsgDialog dynamicInputTextMsgDialog;
    private List<PingBean> pingBeanList = new ArrayList<>();
    private int showType;
    private int showType1;
    private int pos;
    private int mCurrentProgress = 0;
    private boolean isWanChen;

    public List<Boolean> alreadyLikeList = new ArrayList<>();
    private boolean isAll;

    private int page = 1;
    private int pageSize = 10;

    private SmartRefreshLayout refresh,refreshViewPager;
    private int totalCount;


    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_tun_jian3;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initViews();

        initInput();
        initDatas(true);

        TelephonyUtil.getInstance().setOnTelephoneListener(this);
        TelephonyUtil.getInstance().initPhoneListener();

        //在这里停留，让列表界面卡住几百毫秒，给sdk一点预加载的时间，形成秒开的视觉效果
       /* try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/

        initPlayerSDK();
    }


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        try{
            if(getUserVisibleHint()){//界面可见时
                isHidden = true;
                isAll = false;
              //  ToastUtil.toastShortMessage(isHidden + "----setUserVisibleHint");
            }else {
              /*  if (mTXCloudVideoView != null) {
                    mTXCloudVideoView.onPause();
                    if (mTXVodPlayer != null) {
                        mTXVodPlayer.pause();
                    }
                }*/
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }


    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(hidden){
            //...显示的操作
           // isHidden = true;
          //  TXLog.d(TAG, isHidden + "");
         //   ToastUtil.toastShortMessage(isHidden + "----onHiddenChanged");
            RxBus.getDefault().post(EventConstants.QIEHUAN);
        } else {
            mTXVodPlayer.pause();
            //...隐藏的操作
            // isHidden = false;
          //  TXLog.d(TAG,   isHidden + "");
          //  ToastUtil.toastShortMessage(isHidden + "");
          //  ToastUtil.toastShortMessage(isHidden + "----onHiddenChanged");
        }
    }

    private void initPlayerSDK() {
        subscribe = RxBus.getDefault().toObservable(Object.class)
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object object){
                        if (object.equals(EventConstants.HOME) || object.equals(EventConstants.QIEHUAN)){
                            isAll = true;
                            if (mTXCloudVideoView != null) {
                                mTXCloudVideoView.onPause();
                                if (mTXVodPlayer != null) {
                                    mTXVodPlayer.pause();
                                }
                            }
                        }else if (object.equals(EventConstants.FOLLOW)){
                            initDatas(true);
                        }else if (object.equals(EventConstants.ALL)){
                            mRl.setBackgroundColor(getResources().getColor(R.color.black));
                            rvList.setVisibility(View.INVISIBLE);
                            refresh.setVisibility(View.INVISIBLE);
                            refreshViewPager.setVisibility(View.VISIBLE);
                            mPagerAdapter = new MyPagerAdapter();
                            mVerticalViewPager.setAdapter(mPagerAdapter);

                        }else if (object.equals(EventConstants.ALL2)){
                            mRl.setBackgroundColor(getResources().getColor(R.color.white));
                            refresh.setVisibility(View.VISIBLE);
                            rvList.setVisibility(View.VISIBLE);
                            mVerticalViewPager.setVisibility(View.GONE);
                          //  initDatas(true);

                            if (null != mTXCloudVideoView)
                                if (mTXCloudVideoView != null) {
                                    mTXCloudVideoView.onPause();
                                    if (mTXVodPlayer != null) {
                                        mTXVodPlayer.pause();
                                    }
                                }
                        }else if (object.equals(EventConstants.ALL3)){
                            mRl.setBackgroundColor(getResources().getColor(R.color.black));
                            rvList.setVisibility(View.INVISIBLE);
                            refresh.setVisibility(View.INVISIBLE);
                            refreshViewPager.setVisibility(View.VISIBLE);
                        }
                    }
                });
        RxSubscriptions.add(subscribe);
    }

    private void initViews() {
        mTXCloudVideoView = (TXCloudVideoView) rootView.findViewById(R.id.player_cloud_view);

        mVerticalViewPager = (VerticalViewPager) rootView.findViewById(R.id.vertical_view_pager);
        refresh = (SmartRefreshLayout) rootView.findViewById(R.id.refresh);
        refreshViewPager = (SmartRefreshLayout) rootView.findViewById(R.id.refresh_viewPager);
        refreshViewPager.setEnableLoadMore(false);
        mVerticalViewPager.setOffscreenPageLimit(10);

        mPagerAdapter = new MyPagerAdapter();

        mTasksView = (CompletedView) rootView.findViewById(R.id.tasks_view);
        boolean day =  SPUtils.getInstance().getBoolean("today");  //true 任务已做完
        if (day){
            mTasksView.setVisibility(View.GONE);
        }else {
            mTasksView.setVisibility(View.VISIBLE);
        }
      //  mVerticalViewPager.setCurrentItem(0);
        int pro = SPUtils.getInstance().getInt("pro");
        if (pro != -1){
            mTasksView.setProgress(pro);
            mCurrentProgress = pro * 1000;

        }else {
            mTasksView.setProgress(0);
        }


        rvList = rootView.findViewById(R.id.rvList);
        mRl = rootView.findViewById(R.id.rl);

        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 2, LinearLayoutManager.VERTICAL,false);
        //  LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        //配置布局，默认为vertical（垂直布局），下边这句将布局改为水平布局
        //  layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvList.setLayoutManager(layoutManager);
        rvList.setItemAnimator(new DefaultItemAnimator());
        videoAdapter = new VideoAdapter2(TunJianFragment2.this);
        rvList.setAdapter(videoAdapter);
        // videoAdapter.replaceAll(videoListBean, true);

        videoAdapter.setOnItemClickListener(new CommonRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {
                isAdapterFlag = false;
                mRl.setBackgroundColor(getResources().getColor(R.color.black));
                rvList.setVisibility(View.GONE);
                refreshViewPager.setVisibility(View.VISIBLE);
                mVerticalViewPager.setVisibility(View.VISIBLE);
                RxBus.getDefault().post(EventConstants.ALL3);
                RxBus.getDefault().post(EventConstants.HOME2);
                refresh.setVisibility(View.GONE);
              //  mPagerAdapter = new MyPagerAdapter();
              //  mVerticalViewPager.setAdapter(mPagerAdapter);
                mVerticalViewPager.setCurrentItem(i);
                mPagerAdapter.notifyDataSetChanged();
            }
        });



        mVerticalViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                TXLog.d(TAG, "mVerticalViewPager, onPageScrolled position = " + position);
            }

            @Override
            public void onPageSelected(int position) {
                TXLog.d(TAG, "mVerticalViewPager, onPageSelected position = " + position);
                mCurrentPosition = position;

                if (position == videoListBean.size() - 1) {
                    refreshViewPager.setEnableAutoLoadMore(true);
                    refreshViewPager.setEnableLoadMore(true);
                } else {
                    refreshViewPager.setEnableAutoLoadMore(false);
                    refreshViewPager.setEnableLoadMore(false);
                }

                // 滑动界面，首先让之前的播放器暂停，并seek到0
                TXLog.d(TAG, "滑动后，让之前的播放器暂停，mTXVodPlayer = " + mTXVodPlayer);
                if (mTXVodPlayer != null) {  //
                    isPageFlag = true;
                    TXLog.d(TAG, isPageFlag + "-------------------------");
                    mTXVodPlayer.seek(0);
                    mTXVodPlayer.pause();
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

        mVerticalViewPager.setPageTransformer(false, new ViewPager.PageTransformer() {
            @Override
            public void transformPage(View page, float position) {
                TXLog.d(TAG, "mVerticalViewPager, transformPage pisition = " + position + " mCurrentPosition" + mCurrentPosition);
                if (position != 0) {
                    return;
                }

                ViewGroup viewGroup = (ViewGroup) page;
                mTXCloudVideoView = (TXCloudVideoView) viewGroup.findViewById(R.id.player_cloud_view);

                PlayerInfo playerInfo = mPagerAdapter.findPlayerInfo(mCurrentPosition);
                if (playerInfo != null) {
                    playerInfo.vodPlayer.resume();
                    mTXVodPlayer = playerInfo.vodPlayer;
                }
            }
        });
     //   mPagerAdapter = new MyPagerAdapter();
      //  mVerticalViewPager.setAdapter(mPagerAdapter);
    }




    private void initDatas(boolean isRefresh) {
        if (isRefresh) page = 1;
        Map<String, Object> params = new HashMap<>();
        params.put("uId", SPUtils.getInstance().getString(Constants.USERID));
        params.put("pageIndex", page);
        params.put("pageSize", pageSize);
        HttpClient.post(getActivity(), Constants.RECOMMENDVIDEOLIST, params,new CallBack<List<VideoListBean>>() {
            @Override
            public void onSuccess(List<VideoListBean> videoListBeans) {
                    if (isRefresh) {
                        videoListBean.clear();
                        SPUtils.getInstance().put("totalCount", totalCount);
                        videoListBean.addAll(videoListBeans);
                        videoAdapter.replaceAll(videoListBeans, true);
                        refresh.finishRefresh(true);
                        mVerticalViewPager.setAdapter(mPagerAdapter);
                      //  getHomeDataInfo();
                    } else {
                        if (videoListBeans.size() > 0) {
                            refresh.finishLoadMore(true);
                            videoAdapter.addAll(videoListBeans);
                            videoListBean.addAll(videoListBeans);
                            refreshViewPager.finishLoadMore(true);
                            refreshViewPager.setEnableAutoLoadMore(false);
                            refreshViewPager.setEnableLoadMore(false);
                            mPagerAdapter.notifyDataSetChanged();

                        } else {
                            refresh.finishLoadMoreWithNoMoreData();
                            refreshViewPager.finishLoadMoreWithNoMoreData();
                            refreshViewPager.setEnableLoadMore(false);
                        }
                    }
                    page++;

                  //  mPagerAdapter = new MyPagerAdapter();
                  //  mVerticalViewPager.setAdapter(mPagerAdapter);

                    if (mTXCloudVideoView != null) {
                        mTXCloudVideoView.onPause();
                    }
                    if (mTXVodPlayer != null) {
                        mTXVodPlayer.pause();
                    }
                }
        });
    }




    @Override
    public void onRinging() {
        if (mTXVodPlayer != null) {
            mTXVodPlayer.setMute(true);
        }
    }

    @Override
    public void onOffhook() {
        if (mTXVodPlayer != null) {
            mTXVodPlayer.setMute(true);
        }
    }

    @Override
    public void onIdle() {
        if (mTXVodPlayer != null) {
            mTXVodPlayer.setMute(false);
        }
    }


    class MyPagerAdapter extends PagerAdapter {
        ArrayList<PlayerInfo> playerInfoList = new ArrayList<>();

        private boolean isPause;
        private boolean isZhanTing;
        private List<VideoListBean.CarouselProductModelBean> carouselProductModel;

        protected PlayerInfo instantiatePlayerInfo(int position) {
            TXCLog.d(TAG, "instantiatePlayerInfo " + position);

            PlayerInfo playerInfo = new PlayerInfo();
            TXVodPlayer vodPlayer = new TXVodPlayer(getActivity());
            vodPlayer.setRenderRotation(TXLiveConstants.RENDER_ROTATION_PORTRAIT);
            //FIXBUG:FULL_SCREEN 合唱显示不全，ADJUST_RESOLUTION黑边
          //  vodPlayer.setRenderMode(TXLiveConstants.RENDER_MODE_ADJUST_RESOLUTION);

            TXVodPlayConfig config = new TXVodPlayConfig();

            //指定一个本地mp4缓存目录
            File sdcardDir = getActivity().getExternalFilesDir(null);
            if (sdcardDir != null) {
                config.setCacheFolderPath(sdcardDir.getAbsolutePath() + "/txcache");
            }
            config.setMaxCacheItems(10);
            vodPlayer.setConfig(config);
            vodPlayer.setAutoPlay(false);
            vodPlayer.setLoop(false);

            for (VideoListBean videoListBean : videoListBean) {
                TCVideoInfo tcVideoInfo = new TCVideoInfo();
                tcVideoInfo.playurl = videoListBean.getWork_Vidoe();
                mTCLiveInfoList.add(tcVideoInfo);
            }

            TCVideoInfo tcLiveInfo = mTCLiveInfoList.get(position);
            playerInfo.playURL = tcLiveInfo.playurl;
            playerInfo.vodPlayer = vodPlayer;
            playerInfo.reviewstatus = tcLiveInfo.review_status;
            playerInfo.pos = position;
            playerInfoList.add(playerInfo);

            return playerInfo;
        }

        protected void destroyPlayerInfo(int position) {
            while (true) {
                PlayerInfo playerInfo = findPlayerInfo(position);
                if (playerInfo == null) {
                    break;
                }
                playerInfo.vodPlayer.stopPlay(true);
                playerInfoList.remove(playerInfo);

                TXCLog.d(TAG, "destroyPlayerInfo " + position);
            }
        }

        public PlayerInfo findPlayerInfo(int position) {
            for (int i = 0; i < playerInfoList.size(); i++) {
                PlayerInfo playerInfo = playerInfoList.get(i);
                if (playerInfo.pos == position) {
                    return playerInfo;
                }
            }
            return null;
        }

        public PlayerInfo findPlayerInfo(TXVodPlayer player) {
            for (int i = 0; i < playerInfoList.size(); i++) {
                PlayerInfo playerInfo = playerInfoList.get(i);
                if (playerInfo.vodPlayer == player) {
                    return playerInfo;
                }
            }
            return null;
        }

        public void onDestroy() {
            for (PlayerInfo playerInfo : playerInfoList) {
                playerInfo.vodPlayer.stopPlay(true);
            }
            playerInfoList.clear();
        }

        @Override
        public int getCount() {
            return videoListBean.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            TXCLog.i(TAG, "MyPagerAdapter instantiateItem, position = " + position);
         //   TCVideoInfo videoInfo = mTCLiveInfoList.get(position);

            View view = LayoutInflater.from(container.getContext()).inflate(R.layout.view_player_content2, null);
            view.setId(position);

            // 获取此player
            TXCloudVideoView playView = (TXCloudVideoView) view.findViewById(R.id.player_cloud_view);

            //进度条
            final TCPointSeekBar mSeekBarProgress = (TCPointSeekBar) view.findViewById(R.id.superplayer_seekbar_progress);

            final TextView  mTvCurrent = (TextView) view.findViewById(R.id.superplayer_tv_current);

            final TextView  mTvDuration = (TextView) view.findViewById(R.id.superplayer_tv_duration);

            CircleImageView  playerCiv = (CircleImageView) view.findViewById(R.id.player_civ_avatar);
            ImageView ivAdd = (ImageView) view.findViewById(R.id.iv_add);
            ImageView  tvJian = (ImageView) view.findViewById(R.id.tv_jianzan);
            TextView  tvMsg = (TextView) view.findViewById(R.id.tv_msg);
            TextView  tvFan = (TextView) view.findViewById(R.id.tv_fan);
            TextView  tvName = (TextView) view.findViewById(R.id.tv_name);
            TextView  tvTitle = (TextView) view.findViewById(R.id.tv_title);
            TextView  tvInput = (TextView) view.findViewById(R.id.tv_input);
            TextView  tvLike = (TextView) view.findViewById(R.id.tv_like);


            RelativeLayout  rlModel = (RelativeLayout) view.findViewById(R.id.rl_model);
            TextView  tv1 = (TextView) view.findViewById(R.id.tv1);
            TextView  tv2 = (TextView) view.findViewById(R.id.tv2);
            CircleImageView  ivCV = (CircleImageView) view.findViewById(R.id.iv_cv);


            LinearLayout  llJianzan = (LinearLayout) view.findViewById(R.id.ll_jianzan);

            final ImageView  ivReview = (ImageView) view.findViewById(R.id.tx_video_review_status);

            VideoListBean videoBean =  videoListBean.get(position);

            String userId =  SPUtils.getInstance().getString(Constants.USERID);



            carouselProductModel = videoBean.getCarouselProductModel();
            if (carouselProductModel.size()>0){
                rlModel.setVisibility(View.VISIBLE);
                tv1.setText(carouselProductModel.get(0).getName());
                tv2.setText("￥" + carouselProductModel.get(0).getPrice());
                ImageUtil.setImage(ivCV,carouselProductModel.get(0).getImg());
            }else {
                rlModel.setVisibility(View.GONE);
            }

            rlModel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (carouselProductModel.size() > 0) {
                        SPUtils.getInstance().put("Product_Id", carouselProductModel.get(0).getId());
                        ARouter.getInstance().build(RouterActivityPath.Main.ORDER).navigation();
                    }
                }
            });

            if (videoBean.getWork_UserInfoId().equals(userId)){
                ivAdd.setVisibility(View.INVISIBLE);
            }else {
                //0 是否关注
                if (videoBean.getIsFocus() == 0){
                    ivAdd.setVisibility(View.VISIBLE);
                }else {
                    ivAdd.setVisibility(View.INVISIBLE);
                }
            }


            ImageUtil.setImage(playerCiv,videoBean.getWork_UserInfoImage());

            //0 是否点赞  未点赞
            if (videoBean.getIsLike() == 0){
                tvJian.setImageResource(R.mipmap.dianzai3);
            }else {
                tvJian.setImageResource(R.mipmap.live);
            }
          //  tvLike.setText(videoBean.getWoek_LikeNumber() + "");
            tvMsg.setText(videoBean.getWork_RemarkNumber() + "");
            tvFan.setText(videoBean.getWork_ForwardNumber() + "");
            tvName.setText(videoBean.getWork_UserInfoName());
            tvTitle.setText(videoBean.getWork_Title());

            alreadyLikeList.add(videoBean.getIsLike() == 1);  // 已点赞
            if (isAdapterFlag){
                if (alreadyLikeList.get(0)){
                    tvJian.setImageResource(R.mipmap.live);
                }else {
                    tvJian.setImageResource(R.mipmap.dianzai3);  //未点赞
                }
            }else {
                if (alreadyLikeList.get(position)){
                    tvJian.setImageResource(R.mipmap.live);
                }else {
                    tvJian.setImageResource(R.mipmap.dianzai3);  //未点赞
                }
            }


            //评价
            tvMsg.setOnClickListener(v -> {
                showPinDialog(videoBean);
            });

            tvFan.setOnClickListener(v -> {
                showFanDialog(videoBean);
            });

            //加关注
            ivAdd.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("UserId", SPUtils.getInstance().getString(Constants.USERID));
                    params.put("FollowUserId",videoBean.getWork_UserInfoId());
                    HttpClient.get(getActivity(), Constants.ADDFOLLOW, params,new CallBack<BaseBean>() {
                        @Override
                        public void onSuccess(BaseBean baseBean) {
                            ivAdd.setVisibility(View.GONE);
                            videoBean.setIsFocus(1);
                            RxBus.getDefault().post(EventConstants.FOLLOW);
                           // initDatas();
                        }
                    });
                }
            });
            //点赞
            llJianzan.setOnClickListener(v -> {
                Map<String, Object> params = new HashMap<>();
                params.put("uId", SPUtils.getInstance().getString(Constants.USERID));
                params.put("vId",videoBean.getWork_Id());

                //点赞
                if (alreadyLikeList.get(position)){
                    params.put("status", 0 + ""); //取消点赞
                }else {
                    params.put("status",1 + ""); //点赞
                }

                HttpClient.get(getActivity(), Constants.GIVELIKE, params,new CallBack<String>() {
                    @Override
                    public void onSuccess(String baseBean) {
                        if (alreadyLikeList.get(position)){
                            tvJian.setImageResource(R.mipmap.dianzai3);
                            alreadyLikeList.set(position,false);
                        }else{
                            tvJian.setImageResource(R.mipmap.live);
                            alreadyLikeList.set(position,true);
                        }
                    }
                });
            });

            //商品
            tvInput.setOnClickListener(v -> {
                showDialog(videoBean);
            });


            PlayerInfo playerInfo = instantiatePlayerInfo(position);
            playerInfo.playerView = playView;
            playerInfo.vodPlayer.setPlayerView(playView);

            //启动播放
            playerInfo.vodPlayer.startPlay(videoBean.getWork_Vidoe());

            if (playerInfo.vodPlayer.isPlaying()){
               // ivReview.setVisibility(View.GONE);
            }

            //暂停见
            playView.setOnClickListener(v -> {
                isPause = false;
                if (playerInfo.vodPlayer.isPlaying()){
                    //暂停
                    playerInfo.vodPlayer.pause();
                    ivReview.setVisibility(View.VISIBLE);
                    isZhanTing = true;
                    isZhangTing2 = isZhanTing;
                }else {
                    //开始
                    playerInfo.vodPlayer.resume();
                    ivReview.setVisibility(View.INVISIBLE);
                    isZhanTing = false;
                    isZhangTing2 = isZhanTing;
                }
            });

            //右边图标
            playerCiv.setOnClickListener(v -> {

                SPUtils.getInstance().put("uuid", videoBean.getWork_UserInfoId());
                Constants.ISFOCUS = videoBean.getIsFocus();
                ARouter.getInstance().build(RouterActivityPath.Main.PESON).navigation();
              //  getActivity().startActivity(new Intent(getActivity(), PersonalActivity.class).putExtra("uId", videoBean.getWork_UserInfoId())
                                                                                      //  .putExtra("IsFocus", videoBean.getIsFocus()));
                playerInfo.vodPlayer.pause();
                isPause = true;
            });

            //监听播放
            playerInfo.vodPlayer.setVodListener(new ITXVodPlayListener() {

                private int kanPro;

                @Override
                public void onPlayEvent(TXVodPlayer player, int event, Bundle param) {
                    if (event == TXLiveConstants.PLAY_EVT_CHANGE_RESOLUTION) {
                        int width = param.getInt(TXLiveConstants.EVT_PARAM1);
                        int height = param.getInt(TXLiveConstants.EVT_PARAM2);
                        //FIXBUG:不能修改为横屏，合唱会变为横向的
                    } else if (event == TXLiveConstants.PLAY_EVT_PLAY_END) {   //视频播放结束
                        TXLog.i(TAG, "onPlayEvent, event play end, player = " + player);
                        if (videoBean.getIsLook() == 0) { //0 未看过  1 是看过（全部看完）
                            lookWorkrecord(videoBean);
                        }
                        restartPlay();
                    } else if (event == TXLiveConstants.PLAY_EVT_RCV_FIRST_I_FRAME) {// 视频I帧到达，开始播放  翻页开始  第一次
                        PlayerInfo playerInfo = mPagerAdapter.findPlayerInfo(player);
                        if (playerInfo != null) {
                            playerInfo.isBegin = true;
                            videoBean.setOneTan(true);
                        }
                        if (mTXVodPlayer == player) {
                          //  isPageFlag = false;
                            TXLog.i(TAG, "onPlayEvent, event I FRAME, player = " + player);

                         //   mIvCover.setVisibility(View.GONE);
                           // LogReport.getInstance().reportVodPlaySucc(event);
                        }

                    } else if (event == TXLiveConstants.PLAY_EVT_VOD_PLAY_PREPARED) {  //准备 一进来就播放
                        if (mTXVodPlayer == player) {
                            TXLog.i(TAG, "onPlayEvent, event prepared, player = " + player);
                           // mTXVodPlayer.resume();
                           if (!isAll){
                                mTXVodPlayer.resume();
                            }
                        }

                    } else if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) { //开始播放  第二次进来
                        PlayerInfo playerInfo = mPagerAdapter.findPlayerInfo(player);
                        if (playerInfo != null && playerInfo.isBegin) {
                            ivReview.setVisibility(View.GONE);
                            TXCLog.i(TAG, "onPlayEvent, event begin, cover remove");
                            videoBean.setTwoTan(true);
                          //  isPageFlag = false;
                         //   playerInfo.vodPlayer.pause();
                           // ivReview.setVisibility(View.GONE);
                            if (isPause){
                              playerInfo.vodPlayer.pause();
                                ivReview.setVisibility(View.VISIBLE);
                            }
                          //
                        }
                    } else if (event < 0) {
                        if (mTXVodPlayer == player) {
                            TXLog.i(TAG, "onPlayEvent, event prepared, player = " + player);

                          //  LogReport.getInstance().reportVodPlayFail(event);
                        }
                      //  ToastUtil.toastShortMessage("event:" + event);
                    }else if (event == TXLiveConstants.PLAY_EVT_PLAY_PROGRESS){   //播放进度  60秒 == 60000

                        int progress = param.getInt(TXLiveConstants.EVT_PLAY_PROGRESS_MS);    //当前播放进度
                        //播放进度
                      //  KLog.i(progress + "");
                        KLog.i(progress + "--------PROGRESS--------------");
                        int duration = param.getInt(TXLiveConstants.EVT_PLAY_DURATION_MS);
                        //播放时长
                        mTvCurrent.setText(TCTimeUtil.formattedTime(progress/1000));


                        //总时长
                        mTvDuration.setText(TCTimeUtil.formattedTime(duration/1000));


                      //  KLog.i(progress / 1000 + "----progress");
                      //  KLog.i(duration / 1000 + "----duration");

                     //   updateVideoProgress(progress / 1000, duration / 1000);
                        //总时长
                        // playerInfo.vodPlayer.getDuration();

                        //  playerInfo.vodPlayer.getCurrentPlaybackTime();

                        //  playerInfo.vodPlayer.getPlayableDuration();

                        //   KLog.i(playerInfo.vodPlayer.getCurrentPlaybackTime() + "----getCurrentPlaybackTime");
                        //    KLog.i(playerInfo.vodPlayer.getPlayableDuration() + "----getPlayableDuration");
                        //    KLog.i(playerInfo.vodPlayer.getDuration() + "----getDuration");

                        float percentage = (duration/1000) > 0 ? ((float) (progress/1000)  / (float) (duration/1000) ) : 1.0f;

                        int  progress2 = Math.round(percentage * mSeekBarProgress.getMax());

                        KLog.i(videoBean.getIsKan() + "--------isKan--------------" + videoBean.getWork_Id());
                        KLog.i(videoBean.getProgress() + "--------isProgress--------------"+ videoBean.getWork_Id());


                      /*  if (progress2 > 0){
                            if (videoBean.getOneTan()){ //每一次进来
                                mCurrentProgress = progress;
                            }
                            if (videoBean.getTwoTan()){ //第二次进
                                //保存的进度
                                kanPro = videoBean.getProgress();
                                if (progress >= kanPro){
                                    mCurrentProgress += progress;
                                    videoBean.setProgress(progress);
                                }
                            }
                        }*/


                       if (progress2 > 0) {  //进度条大于0
                            boolean isSaveKan  =  SPUtils.getInstance().getBoolean(videoBean.getWork_Id() + videoBean.getIsKan() + "progress");
                            int mProgress  =  SPUtils.getInstance().getInt("pro");
                            if (mProgress  != -1){
                                //  mCurrentProgress = mProgress;
                            }

                            if (isSaveKan || videoBean.getIsKan()) {   //看过  true 是第一次进来
                                int kanPro  =  SPUtils.getInstance().getInt(videoBean.getWork_Id() + "progresssss");

                                // kanPro = videoBean.getProgress();
                                if (progress >= kanPro) {  //当前播放进度大于 等于 存入的进度后
                                    if (mTXVodPlayer.isPlaying()){ //是否播放  flase 是暂停
                                        mCurrentProgress += 1000;
                                    }else {

                                    }
                                    videoBean.setProgress(progress);
                                }
                            } else {  //没看过
                                if (mTXVodPlayer.isPlaying()){ //是否播放
                                    mCurrentProgress += 1000;
                                }else {

                                }
                                videoBean.setProgress(progress);  //进度
                                videoBean.setIsKan(true);  //看过
                                SPUtils.getInstance().put(videoBean.getWork_Id() + videoBean.getIsKan() + "progress", true);
                            }

                            SPUtils.getInstance().put(videoBean.getWork_Id() + "progresssss", videoBean.getProgress());
                        }

                        KLog.i(progress2 + "--------PROGRESS222222222--------------");

                        mSeekBarProgress.setProgress(progress2);

                        //今日任务
                        float percentage2 = (mCurrentProgress/1000) > 0 ? ((float) (mCurrentProgress/1000)) : 1.0f;

                        int  progress3 = Math.round(percentage2);

                        boolean today = SPUtils.getInstance().getBoolean("today");
                        if (progress2 != 0) {
                            if (progress3 >= 300){
                                if (today){   //false
                                    return;
                                }
                                mTasksView.setVisibility(View.GONE);
                            //    ToastUtil.toastShortMessage("今日任务已完成");
                                SPUtils.getInstance().put("today", true);

                                //  SPUtils.getInstance().put("day", true);
                              //  isWanChen = true;
                                beanBagrecord();

                            }else {
                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        SPUtils.getInstance().put("today", false);
                                        mTasksView.setProgress(progress3);
                                        SPUtils.getInstance().put("pro", progress3);

                                        String day = UItils.getDayTime2();
                                        SPUtils.getInstance().put("yesToday", day);
                                    }
                                });
                            }
                        }



                      //    new Thread(new ProgressRunable()).start();
                        //   updateVideoProgress(playerInfo.vodPlayer.getPlayableDuration(), playerInfo.vodPlayer.getDuration());
                        // KLog.i(progress  / duration );
                    }
                }

                @Override
                public void onNetStatus(TXVodPlayer txVodPlayer, Bundle bundle) {

                }
            });

            playerInfo.vodPlayer.getDuration();
            playerInfo.vodPlayer.getCurrentPlaybackTime();
            float a = playerInfo.vodPlayer.getCurrentPlaybackTime() / playerInfo.vodPlayer.getDuration();
            KLog.json("hhh",a + "");

            container.addView(view);
            return view;
        }


       /* class ProgressRunable implements Runnable {
            @Override
            public void run() {
                mTasksView.setProgress(mCurrentProgress);
            }
        }*/

        /**
         *  商品
         */
        private void showDialog(VideoListBean videoBean) {
            dialogHead = new Dialog(getActivity(), R.style.ActionSheetDialogStyle);
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_video, null);
            RecyclerView rlShop = view.findViewById(R.id.rl_shop);
            LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
            //配置布局，默认为vertical（垂直布局），下边这句将布局改为水平布局
            layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            rlShop.setLayoutManager(layoutManager);
            rlShop.setItemAnimator(new DefaultItemAnimator());
            ShowShopAdapter showShopAdapter = new ShowShopAdapter(getActivity());
            rlShop.setAdapter(showShopAdapter);


            view.findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialogHead.dismiss();
                }
            });

            dialogHead.setContentView(view);
            Window window = dialogHead.getWindow();
            if (window == null) {
                return;
            }
            //宽高最大
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
            dialogHead.setCanceledOnTouchOutside(true);
            dialogHead.show();
            //显示对话框//设置Dialog从窗体底部弹出
            window.setGravity(Gravity.BOTTOM);
            //获取窗体的属性
            WindowManager.LayoutParams lp = window.getAttributes();
            //设置Dialog距离底部的距离
            //将属性设置给窗体
            window.setAttributes(lp);

            Map<String, Object> params = new HashMap<>();
            params.put("uId", videoBean.getWork_UserInfoId());
            params.put("pageIndex", 1);
            params.put("pageSize", 50);
            HttpClient.post(view.getContext(), Constants.WORKPRODUCTLIST, params,new CallBack<List<ShopShowBean>>() {
                @Override
                public void onSuccess(List<ShopShowBean> shopShowBeans) {
                    showShopAdapter.replaceAll(shopShowBeans, true);
                }
            });
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            TXCLog.i(TAG, "MyPagerAdapter destroyItem, position = " + position);

            destroyPlayerInfo(position);

            container.removeView((View) object);
        }
    }

    private void beanBagrecord() {
        Map<String, Object> params = new HashMap<>();
        params.put("uId",SPUtils.getInstance().getString(Constants.USERID));
        HttpClient.get(getActivity(), Constants.BEANBAGRECORD, params,new CallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean result) {
                SPUtils.getInstance().put("today", true);
                String day = UItils.getDayTime2();
                SPUtils.getInstance().put("yesToday", day);
            }
        });
    }

    /**
     * 转发
     * @param videoBean
     */
    private void showFanDialog(VideoListBean videoBean) {
        Dialog  dialogHead = new Dialog(getActivity(), R.style.ActionSheetDialogStyle);
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_fan, null);

        view.findViewById(R.id.ll_wei).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Platform platform = ShareSDK.getPlatform(Wechat.NAME);
                Platform.ShareParams shareParams = new  Platform.ShareParams();
                shareParams.setTitle("今网播");
                shareParams.setText("");
              //  shareParams.setImageUrl(videoBean.getWork_Image());
                shareParams.setImageUrl(videoBean.getWork_Image());
                shareParams.setUrl(videoBean.getWork_Vidoe());
                //分享网页
                shareParams.setShareType(Platform.SHARE_WEBPAGE);
                platform.share(shareParams);
                dialogHead.dismiss();
            }
        });
        view.findViewById(R.id.ll_zhi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Platform platform = ShareSDK.getPlatform(WechatMoments.NAME);
                Platform.ShareParams shareParams = new  Platform.ShareParams();
                shareParams.setTitle("今网播");
                shareParams.setText("这是一个有趣的应用");
                //  shareParams.setImageUrl(videoBean.getWork_Image());
                shareParams.setImageUrl(videoBean.getWork_Image());
                shareParams.setUrl(videoBean.getWork_Vidoe());
                //分享网页
                shareParams.setShareType(Platform.SHARE_WEBPAGE);
                platform.share(shareParams);
                dialogHead.dismiss();
            }
        });

        dialogHead.setContentView(view);
        Window window = dialogHead.getWindow();
        if (window == null) {
            return;
        }
        //宽高最大
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        //显示对话框//设置Dialog从窗体底部弹出
        dialogHead.setCanceledOnTouchOutside(true);
        dialogHead.show();
        window.setGravity(Gravity.BOTTOM);
        //获取窗体的属性
        WindowManager.LayoutParams lp = window.getAttributes();
        //设置Dialog距离底部的距离
        //将属性设置给窗体
        window.setAttributes(lp);

    }

    /**
     视频观看记录
  */
    private void lookWorkrecord(VideoListBean videoBean) {
        Map<String, Object> params = new HashMap<>();
        params.put("wId",videoBean.getWork_Id());
        params.put("uId",SPUtils.getInstance().getString(Constants.USERID));
        HttpClient.get(getActivity(), Constants.LOOKWORKRECORD, params,new CallBack<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                videoBean.setIsLook(1);
            }
        });
    }

    private String remark_id;
    private String replyId;

    private void showPinDialog(VideoListBean videoBean) {
        Dialog  dialogHead = new Dialog(getActivity(), R.style.ActionSheetDialogStyle);
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_video, null);
        RecyclerView rlShop = view.findViewById(R.id.rl_shop);
        tvNme = view.findViewById(R.id.tv_num);
        LinearLayout llSend = view.findViewById(R.id.ll_send_or_cancel);
        TextView etInput = view.findViewById(R.id.et_input_message);
        TextView tvSend = view.findViewById(R.id.tv_send);

        llSend.setVisibility(View.VISIBLE);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        //配置布局，默认为vertical（垂直布局），下边这句将布局改为水平布局
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rlShop.setLayoutManager(layoutManager);
        rlShop.setItemAnimator(new DefaultItemAnimator());
        pingJiaListAdapter = new PingJiaListAdapter(getActivity());
        rlShop.setAdapter(pingJiaListAdapter);

        etInput.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showType1 = 1;
                dynamicInputTextMsgDialog.setShowType();

            }
        });


        dynamicInputTextMsgDialog.setOnSendClickListener(new DynamicInputTextMsgDialog.OnSendClickListener() {
            @Override
            public void onSendClick(String etInput) {
                if (TextUtils.isEmpty(etInput)){
                    ToastUtil.toastShortMessage("请输入评价内容");
                    return;
                }
                if (showType1 == 1){
                    Map<String, Object> params = new HashMap<>();
                    params.put("userId", SPUtils.getInstance().getString(Constants.USERID));
                    params.put("parentId","");
                    params.put("replyId","");
                    params.put("remark_Content",etInput);
                    params.put("workId",videoBean.getWork_Id());
                    HttpClient.post(getActivity(), Constants.ADDREMARK, params,new CallBack<TolalBean>() {
                        @Override
                        public void onSuccess(TolalBean result) {
                            remarkList(videoBean);
                        }
                    });
                }else {
                    Map<String, Object> params = new HashMap<>();
                    params.put("userId", SPUtils.getInstance().getString(Constants.USERID));
                    params.put("parentId",remark_id);
                    params.put("replyId",replyId);
                    params.put("remark_Content",etInput);
                    params.put("workId",videoBean.getWork_Id());
                    HttpClient.post(getActivity(), Constants.ADDREMARK, params,new CallBack<TolalBean>() {
                        @Override
                        public void onSuccess(TolalBean result) {
                            remarkList(videoBean);

                          /*  Map<String, Object> params = new HashMap<>();
                            params.put("workId", videoBean.getWork_Id());
                            params.put("parentId", remark_id);
                            params.put("pageIndex",pos + 1);
                            params.put("pageSize",10);
                            HttpClient.post(getActivity(), Constants.CHILDREMARKLIST, params,new CallBack<List<PingBean>>() {
                                @Override
                                public void onSuccess(List<PingBean> pingBeans) {

                                }
                            });*/
                        }
                    });
                }
            }
        });


        view.findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogHead.dismiss();
            }
        });


        dialogHead.setContentView(view);
        Window window = dialogHead.getWindow();
        if (window == null) {
            return;
        }
        //宽高最大
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        //显示对话框//设置Dialog从窗体底部弹出
        dialogHead.setCanceledOnTouchOutside(true);
        dialogHead.show();
        window.setGravity(Gravity.BOTTOM);
        //获取窗体的属性
        WindowManager.LayoutParams lp = window.getAttributes();
        //设置Dialog距离底部的距离
        //将属性设置给窗体
        window.setAttributes(lp);

        remarkList(videoBean);

        pingJiaListAdapter.setOnItemClickListener(new CommonRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {
                showType1 = 2;
                pos = i;
                dynamicInputTextMsgDialog.setShowType();
                remark_id = pingBeanList.get(i).getRemark_Id();
                dynamicInputTextMsgDialog.etInputMessage.setText("@" + pingBeanList.get(i).getUserName() + " ");
                dynamicInputTextMsgDialog.etInputMessage.setSelection(dynamicInputTextMsgDialog.etInputMessage.getText().toString().length());
            }
        });

        pingJiaListAdapter.setOnSendClickListener(new PingJiaListAdapter.OnSetClickListener() {
            @Override
            public void onSendClick(String text, String text2,String name) {
                showType1 = 2;
                remark_id = text;
                replyId = text2;
                dynamicInputTextMsgDialog.setShowType();
                dynamicInputTextMsgDialog.etInputMessage.setText("@" + name);
                dynamicInputTextMsgDialog.etInputMessage.setSelection(dynamicInputTextMsgDialog.etInputMessage.getText().toString().length());
            }
        });
    }

    private void initInput() {
        dynamicInputTextMsgDialog = new DynamicInputTextMsgDialog(getActivity());

        refresh.setOnRefreshListener(refreshLayout -> initDatas(true));
        refresh.setOnLoadMoreListener(refreshLayout ->initDatas(false));

        refreshViewPager.setOnLoadMoreListener(refreshLayout ->initDatas(false));
    }

    /**
     * 评价列表
     */
    private void remarkList(VideoListBean videoBean) {
        Map<String, Object> params = new HashMap<>();
        params.put("workId", videoBean.getWork_Id());
        params.put("pageIndex",1);
        params.put("pageSize",10);
        HttpClient.post(getActivity(), Constants.REMARKLIST, params,new CallBack<List<PingBean>>() {
            @Override
            public void onSuccess(List<PingBean> pingBeans) {
                pingBeanList.clear();
                pingBeanList.addAll(pingBeans);
                pingJiaListAdapter.replaceAll(pingBeans,true);
                tvNme.setText("共" + pingBeans.size() + "条评论");
            }
        });
    }

    private void restartPlay() {
        if (mTXVodPlayer != null) {
            mTXVodPlayer.resume();
        }
    }




    @Override
    public void onResume() {
        super.onResume();
        if (mTXCloudVideoView != null) {
            mTXCloudVideoView.onResume();
        }
        if (mTXVodPlayer != null) {
           // mTXVodPlayer.resume();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if (mTXCloudVideoView != null) {
            mTXCloudVideoView.onPause();
        }
        if (mTXVodPlayer != null) {
            mTXVodPlayer.pause();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mTXCloudVideoView != null) {
            mTXCloudVideoView.onDestroy();
            mTXCloudVideoView = null;
        }

        if (null != mPagerAdapter) mPagerAdapter.onDestroy();
        // true 代表清除最后一帧画面
        stopPlay(true);
        mTXVodPlayer = null;

        TelephonyUtil.getInstance().uninitPhoneListener();
    }

    protected void stopPlay(boolean clearLastFrame) {
        if (mTXVodPlayer != null) {
            mTXVodPlayer.stopPlay(clearLastFrame);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        RxSubscriptions.remove(subscribe);
    }
}
